#include <iostream>
#include <cstdlib>
#include <sys/socket.h>
#include <signal.h>
#include <list>
#include <sys/types.h>
#include <pwd.h>
#include "../socks/sock.h"
#include "../socks/sockdist.h"

typedef struct Client {
	int desc;
	//string nom;
	struct sockaddr_in BR;
	socklen_t lg;
} Client;


class tcp_server
{
	private :
		Sock BR;
		int descBR;
		
		fd_set set;
		list<Client*> clients;
		int descMax;
		
		bool running;
		
	public :
		tcp_server(short int port);
		~tcp_server();
		
		void update_fd();
		
		bool tcp_send(string data, int desc = -1);
		string tcp_recv(int desc);
		
		void add_client();
		void remove_client(int desc);
		
		void run();
		void quit(int signal);
};


class tcp_client
{
	private :
		Sock BR;
		int descBR;

		SockDist BR_server;
		struct sockaddr_in * addr_BR_server;
		int lg_BR_server;

		fd_set set;
		list<int> descs;
		int descMax;
		
		bool running;
		
	public :
		tcp_client(short int port, char* ip);
		~tcp_client();

		void update_fd();

		bool tcp_send(string data, int desc = -1);
		string tcp_recv(int desc = -1);

		void add_stdin();

		void run();
		void quit(int signal);
};
